using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.IO;
using System.Net;
using MosaicManager;
using Fullsix.Common.Configuration;


public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void lnkSalva_Click(object sender, EventArgs e)
    {
        string nome = DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString();

        CreaFileAmiciIdb(nome);
        //Salvo l'immagine che mi passa l'utente e richiamo l'handler,
        //passando il guid dell'utente

        if (!string.IsNullOrEmpty(fuFoto.FileName))
        {
            if (CheckExtension(fuFoto.FileName))
            {
                if (fuFoto.HasFile)
                {
                    string estensione = Path.GetExtension(fuFoto.FileName);
                    string completePath = Server.MapPath(string.Format("{0}{1}/{1}{2}", ConfigurationProxy.ReadConfigurationSetting("CartellaImmagini"), nome, estensione));                    
                    

                    fuFoto.SaveAs(completePath);

                    Response.Redirect(string.Format("Handler/Handler.ashx?IdUtente={0}", nome + estensione));
                }
            }
        }
    }

    protected bool CheckExtension(string path)
    {
        if (Path.GetExtension(path).Equals(".jpg") || Path.GetExtension(path).Equals(".gif"))
        {
            return true;
        }
        else
        {
            return false;
        }        
    }


    protected void CreaFileAmiciIdb(string nomeUtente)
    {
        string[] filePaths = txtFotoLink.Text.Split(',');

        ManageMosaic mMosaic = new ManageMosaic();
        mMosaic.CreateXMlFriends(filePaths, nomeUtente, Context);
    }   
}
